package org.example.edusmart.service.impl;

import org.example.edusmart.dao.UserDao;
import org.example.edusmart.pojo.UserPojo;
import org.example.edusmart.pojo.UserRolePojo;
import org.example.edusmart.request.admin.RoleListPojo;
import org.example.edusmart.request.admin.UserInfoPojo;
import org.example.edusmart.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserPojo checkUserByUsername(String username) {
        return userDao.getUserByUsername(username);
    }

    @Override
    public UserPojo checkEmail(String email) {

        return userDao.getUserByEmail(email);
    }

    @Override
    public void addUser(HashMap<String, Object> insertParameter) {
        userDao.creatUser(insertParameter);
    }

    @Override
    public void insertUserRole(UserRolePojo userRole) {
        userDao.insertUserRole(userRole);
    }

    @Override
    public void insertNumber(HashMap<String, Object> number) {
        userDao.insertNumberByUsernameAndEmail(number);
    }

    @Override
    public List<String> checkPermission(Integer userID) {
        return userDao.getPermissionByUserId(userID);
    }

    @Override
    public UserPojo getUserByUserId(String userId) {
        return userDao.getUserByUserId(userId);
    }

    @Override
    public void changePassword(HashMap<String, Object> newPassword) {
        userDao.changeUserPassword(newPassword);
    }

    @Override
    public void changeUserInfo(HashMap<String, Object> info) {
        userDao.changeUserInfoByUsernameAndEmail(info);
    }

    @Override
    public List<HashMap<String, Object>> allUserInfo(UserInfoPojo userInfoPojo) {
        return userDao.getUserByUsernameOrNumber(userInfoPojo);
    }

    @Override
    public List<HashMap<String, Object>> getRoleList(RoleListPojo roleListPojo) {
        return userDao.getRoleNameByNumber(roleListPojo);
    }

    @Override
    public Integer changeUserRoleByUserid(HashMap<String, Object> info) {
        return userDao.changeUserRoleByUserid(info);
    }

    @Override
    public String getUserRole(String userId) {
        return userDao.getUserRoleByUserId(userId);
    }

}
